package com.ln.property_control.controller;


import com.ln.property_control.pojo.ClaimVo;
import com.ln.property_control.pojo.Department;
import com.ln.property_control.pojo.PropertyVo;
import com.ln.property_control.service.ClaimService;
import com.ln.property_control.utils.GetId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("claim")
public class ClaimController {
    @Autowired
    private ClaimService claimService;
    //资产报状态修显示
    @RequestMapping("/findAllByBorrow")
    @ResponseBody
    public Map<String,Object>findAllByBorrow(Integer page, Integer limit){
            Map<String, Object> map = claimService.findAllByBorrow(page, limit);
            return map;
    }
    @RequestMapping("/goclaimoperation")
    public String goclaimoperation(String borrowNumber, Model model){
        ClaimVo claimVo = claimService.selectByBorrowNumber(borrowNumber);
        model.addAttribute("claimVo", claimVo);
        return "asset/claim/operation";
    }
    @RequestMapping("/departmentByParentId")
    @ResponseBody
    public List<Department> departmentByParentId(int parentId) {
        List<Department> departments = claimService.departmentByParentId(parentId);
        return departments;
    }
//    @RequestMapping("/insertByClaim")
//    @ResponseBody
//    public String insertByClaim(ClaimVo claimVo){
//        String s = claimService.insertByClaim(claimVo);
//        return s;
//    }
    @RequestMapping("/saveByClaim")
    @ResponseBody
    public int saveByClaim(ClaimVo claimVo){
        int i = claimService.saveByClaim(claimVo);
        return i;
    }
    @RequestMapping("/findAllByStatus")
    @ResponseBody
    public Map<String,Object>findAllByStatus(Integer page, Integer limit,String status){
        Map<String, Object> map = claimService.findAllByStatus(page, limit,status);
        return map;
    }
    @RequestMapping("/gobackOperation")
    public String gobackOperation(String borrowNumber, Model model){
        ClaimVo claimVo = claimService.selectByBorrowNumber(borrowNumber);
        model.addAttribute("claimVo", claimVo);
        return "asset/claim/backOperation";
    }

    @RequestMapping("/findAllByHistory")
    @ResponseBody
    public Map<String,Object>findAllByHistory(Integer page, Integer limit,String status){
        Map<String, Object> map = claimService.findAllByHistory(page, limit,status);
        return map;
    }


    @RequestMapping("/findAllBypropertyVo")
    public String findAllBypropertyVo(Model model) {
        List<PropertyVo> allBypropertyVo = claimService.findAllBypropertyVo();
        model.addAttribute("pro", allBypropertyVo);
        return "asset/claim/operation";
    }

    @RequestMapping("/insertByDepProMidd")
    @ResponseBody
    public String insertByDepProMidd(@RequestParam("property_id") List<String> property_id,ClaimVo claimVo){
        String s = claimService.insertByClaim(claimVo);
        String s1 = claimService.insertByDepProMidd(claimVo.getBorrowNumber(), property_id);
        return s1;
    }

    @RequestMapping("/findByProperId")
    @ResponseBody
    public List<PropertyVo> findByProperId(String property_dep_id) {
        List<PropertyVo> byProperId = claimService.findByProperId(property_dep_id);
        return byProperId;
    }

    @RequestMapping("/findByProClaimID")
    public String  findByProClaimID(String borrowNumber , Model model) {

        List<ClaimVo> byProClaimID = claimService.findByProClaimID(borrowNumber);
        model.addAttribute("claim", byProClaimID);
        return "asset/claim/operation";
    }

    @RequestMapping("/findByBackProClaimID")
    public String  findByBackProClaimID(String borrowNumber , Model model) {

        List<ClaimVo> byProClaimID = claimService.findByProClaimID(borrowNumber);
        model.addAttribute("claim", byProClaimID);
        return "asset/claim/backOperation";
    }
}
